package Zoo.Handler;


/*
 *  重要！！（配套Loginview）
 * */



import Zoo.Entity.ZoomenEntity;
import Zoo.Impl.LeaderService1Impl;
import Zoo.Service.LeaderService1;
import Zoo.View.LeaderView.DeleteZoomenView;
import Zoo.View.LeaderView.LeaderView1;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DeleteZoomenViewHandler implements ActionListener {
    private DeleteZoomenView deleteZoomenView;
    private LeaderView1 leaderView1;


    public DeleteZoomenViewHandler(DeleteZoomenView deleteZoomenView, LeaderView1 leaderView1) {
        this.deleteZoomenView=deleteZoomenView;
        this.leaderView1=leaderView1;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("删除".equals(text)){
            LeaderService1 leaderService1=new LeaderService1Impl();
            ZoomenEntity zoomenEntity =deleteZoomenView.buildDeletedZoomenEntity();
            boolean deleteResult=leaderService1.delete(zoomenEntity);
            if(deleteResult){
                //重新加载表格查到最新数据
                leaderView1.reloadTable();
                deleteZoomenView.dispose();
            }else{
                JOptionPane.showMessageDialog(deleteZoomenView,"修改失败");

            }

        }
    }

}
